<?php
session_start();
if (isset($_SESSION["account"])) {
?>
<?php require_once('common/header.php'); ?>
<?php require_once('common/sidebar.php'); ?> 
<div class="main-content app-content mt-0">
                <div class="side-app">
                    <!--占位-->
                            <div class="card"> </div>
                            <!--占位-->
                    <!-- CONTAINER -->
                    <div class="main-container container-fluid">
                            <div class="row">
                            <div class="col-sm-12 col-md-12">
                              <?php
                                session_start();
                                include_once("../untils/conn.php");
                                mysqli_query($con, "set names utf8");
                                
                                // 获取当前正在登录的账号信息的代理
                                $proxy_acc = $_SESSION["account"];
                                
                                // 查询proxy表中的数据
                                $query = "SELECT proxy_rename_sta FROM proxy WHERE proxy_acc = '$proxy_acc'";
                                $result = mysqli_query($con, $query);
                                $row = mysqli_fetch_assoc($result);
                                
                                if ($row) {
                                    $proxy_rename_sta = $row['proxy_rename_sta'];
                                ?>

                                <div class="panel-body tabs-menu-body p-0 border-0">
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="tab5">
                                            <div class="card" style=" float: left;">
                                                <div class="card-body">
                                                    <div class="mb-2 h4 text-dark " >
                                                        实名信息
                                                    </div>
                                                        <p>真实姓名:<t id="rename"></p>
                                                        <p>手机号码:<t id="phone"></p>
                                                        <p>身份证号:<t id="card_uid"></p>
                                                        
                                                 <?php
                                                    if ($proxy_rename_sta == 0) {
                                                        // 未实名认证
                                                        echo '<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#rename-modal" data-bs-whatever="@mdo">实名认证</button>';
                                                    } elseif ($proxy_rename_sta == 1) {
                                                        // 已实名认证
                                                        echo '<a href="" class="btn btn-secondary">已实名</a>';
                                                    }
                                                    ?>
                                                </div>
                                                <!-- Input modal -->
                                                <div class="modal fade" id="rename-modal">
                                                  <div class="modal-dialog" role="document">
                                                    <div class="modal-content modal-content-demo">
                                                      <div class="modal-header">
                                                        <h6 class="modal-title">实名认证</h6>
                                                        <button class="btn-close" data-bs-dismiss="modal" aria-label="Close">
                                                          <span aria-hidden="true">×</span>
                                                        </button>
                                                      </div>
                                                      <div class="modal-body">
                                                        <form>
                                                          <div class="mb-3">
                                                            <label for="proxy_rename" class="col-form-label">姓名:</label>
                                                            <input type="text" class="form-control" id="proxy_rename" required>
                                                          </div>
                                                          <div class="mb-3">
                                                            <label for="proxy_uid" class="col-form-label">身份证号:</label>
                                                            <input type="text" class="form-control" id="proxy_uid" required>
                                                          </div>
                                                          <div class="mb-3">
                                                            <label for="proxy_phone" class="col-form-label">手机号码:</label>
                                                            <input type="text" class="form-control" id="proxy_phone" required>
                                                          </div>
                                                          <div class="mb-3">
                                                            <label for="verification_code" class="col-form-label">验证码:</label>
                                                            <input type="text" class="form-control" id="verification_code" required>
                                                          </div>
                                                          <div class="mb-3">
                                                            <button class="btn btn-primary" id="get_verification_code">获取验证码</button>
                                                            <span id="countdown"></span>
                                                          </div>
                                                        </form>
                                                      </div>
                                                      <div class="modal-footer">
                                                        <button class="btn ripple btn-success" type="button" id="submit_btn_rename">保存提交</button>
                                                        <button class="btn ripple btn-danger" data-bs-dismiss="modal" type="button">取消</button>
                                                      </div>
                                                    </div>
                                                  </div>
                                                </div>
                                                <!-- End Input modal -->
                                                <!--<a href=""> <p class="btn btn-secondary" >修改资料</p></a>-->
                                            </div>
                                            <?php
                                                } else {
                                                    
                                                }
                                                ?>
                                            <!--<div class="card">-->
                                            <!--<div class="card-body">-->
                                            <!--    <div class="mb-2 h4 text-dark">-->
                                            <!--        微信绑定-->
                                            <!--    </div>-->
                                            <!--    <p>微信头像:</p>-->
                                            <!--    <p>微信昵称:</p>-->
                                                <!--<a href=""> <p class="btn btn-secondary">绑定账号</p></a>-->
                                            <!--    <button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#wechat-modal" data-bs-whatever="@mdo">绑定微信</button>-->
                                            <!--</div>-->
                                            <!-- Input modal -->
                                            <div class="modal fade" id="wechat-modal">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content modal-content-demo">
                                                        <div class="modal-header">
                                                            <h6 class="modal-title">绑定微信</h6>
                                                            <button class="btn-close" data-bs-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">×</span>
                                                            </button>
                                                        </div>
                                                        <div class="modal-body">
                                                            <form>
                                                                <div>
                                                                    <img src="" alt="这是生成微信公众号的二维码">
                                                                </div>
                                                            </form>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button class="btn ripple btn-success" type="button" id="submit_btn">保存提交</button>
                                                            <button class="btn ripple btn-danger" data-bs-dismiss="modal" type="button">取消</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- End Datepicker modal -->
                                        </div>

                                            <div class="card">
                                                <div class="card-body">
                                                    <div class="mb-2 h4 text-dark " >
                                                        支付宝账号
                                                    </div>
                                                        <p>姓名:<t id="alipay"></t></p>
                                                        <p>账号:<t id="alipay_acc"></t></p>
                                                        <!--<a href=""> <p class="btn btn-secondary">绑定账号</p></a>-->
                                                        <button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#alipay-modal" data-bs-whatever="@mdo">绑定账号</button>
                                                </div>
                                                <!-- Inout modal -->
                                                <div class="modal fade" id="alipay-modal">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content modal-content-demo">
                                                            <div class="modal-header">
                                                                <h6 class="modal-title">绑定支付宝</h6>
                                                                <button class="btn-close" data-bs-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">×</span>
                                                                </button>
                                                            </div>
                                                            <div class="modal-body">
                                                                <form>
                                                                  <div class="mb-3">
                                                                    <label for="alipay_name" class="col-form-label">姓名:</label>
                                                                    <input type="text" class="form-control" id="alipay_name" required>
                                                                  </div>
                                                                  <div class="mb-3">
                                                                    <label for="alipay_acc_input" class="col-form-label">账号:</label>
                                                                    <input type="text" class="form-control" id="alipay_acc_input" required>
                                                                  </div>
                                                                </form>
                                                              </div>
                                                            <div class="modal-footer">
                                                                <button class="btn ripple btn-success" type="button" id="submit_btn_alipay">保存提交</button>
                                                                <button class="btn ripple btn-danger" data-bs-dismiss="modal" type="button">取消</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <!-- End Datepicker modal -->
                                            </div>
                                            <div class="card">
                                                <div class="card-body">
                                                    <div class="mb-2 h4 text-dark " >
                                                        银行卡账号
                                                    </div>
                                                        <p>姓名:<t id="bank_name"></t></p>
                                                        <p>账号:<t id="bank_acc"></t></p>
                                                        <p>银行:<t id="proxy_bank_name"></t></p>
                                                        <p>支行:<t id="proxy_bank_zh"></t></p>
                                                        <!--<a href=""> <p class="btn btn-secondary">绑定账号</p></a>-->
                                                        <button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#bank-modal" data-bs-whatever="@mdo">绑定账号</button>
                                                </div>
                                                         <!-- Inout modal -->
                                                <div class="modal fade" id="bank-modal">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content modal-content-demo">
                                                            <div class="modal-header">
                                                                <h6 class="modal-title">绑定银行卡</h6>
                                                                <button class="btn-close" data-bs-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">×</span>
                                                                </button>
                                                            </div>
                                                            <div class="modal-body">
                                                                <form>
                                                                  <div class="mb-3">
                                                                    <label for="bank_names" class="col-form-label">姓名:</label>
                                                                    <input type="text" class="form-control" id="bank_names" required>
                                                                  </div>
                                                                  <div class="mb-3">
                                                                    <label for="bank_accs" class="col-form-label">账号:</label>
                                                                    <input type="text" class="form-control" id="bank_accs" required>
                                                                  </div>
                                                                  <div class="mb-3">
                                                                      <label for="proxy_bank_names" class="col-form-label">银行名称:<p style="color:red">只提供平台支持的银行</p></label>
                                                                      <select class="form-control" id="proxy_bank_names" required>
                                                                        <option value="中国银行">中国银行</option>
                                                                        <option value="工商银行">工商银行</option>
                                                                        <option value="招商银行">招商银行</option>
                                                                        <option value="邮政银行">邮政银行</option>
                                                                        <option value="交通银行">交通银行</option>
                                                                        <option value="建设银行">建设银行</option>
                                                                        <option value="农商银行">农商银行</option>
                                                                      </select>
                                                                    </div>
                                                                  <div class="mb-3">
                                                                    <label for="proxy_bank_zhs" class="col-form-label">银行支行:</label>
                                                                    <input type="text" class="form-control" id="proxy_bank_zhs" required>
                                                                  </div>
                                                                </form>
                                                              </div>
                                                            <div class="modal-footer">
                                                                <button class="btn ripple btn-success" type="button" id="submit_btn_banks">保存提交</button>
                                                                <button class="btn ripple btn-danger" data-bs-dismiss="modal" type="button">取消</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <!-- End Datepicker modal -->
                                            </div>
                                        </div>
                                       
                                </div>
                              
                            </div>
                        </div>
                        <!-- End Row -->
                    </div>
                    <!-- CONTAINER CLOSE -->
    <script src="assets/js/jquery.min.js"></script>
    <script>
    $.ajax({
    url: "controller/Proxy.php",
    type: "POST",
    dataType: "json",
    success: function(data) {
        

       // 获取成功后的代码
        $("#avatar").attr("src", data.avatar);
        $("#name").text(data.name);
        $("#account").text(data.account);
        $("#rename").text(data.rename);
        $("#phone").text(data.phone);
        $("#card_uid").text(data.card_uid);
        $("#alipay").text(data.alipay);
        $("#alipay_acc").text(data.alipay_acc);
        $("#bank_name").text(data.bank_name);
        $("#bank_acc").text(data.bank_acc);
        $("#proxy_bank_name").text(data.proxy_bank_name);
        $("#proxy_bank_zh").text(data.proxy_bank_zh);
        $("#type").text(data.type);
    },
    
    error: function() {
        // 获取失败后的代码
        alert("获取代理信息失败");
    }
});

// <!-- 这里验证手机号 -->
$(document).ready(function() {
    // 验证手机号码格式
    function validatePhoneNumber(phoneNumber) {
        var regex = /^1[0-9]{10}$/;
        return regex.test(phoneNumber);
    }

    // 点击获取验证码按钮
    $("#get_verification_code").click(function() {
        var phoneNumber = $("#proxy_phone").val();

        // 验证手机号码是否为空
        if (phoneNumber === "") {
            alert("请输入手机号码");
            return;
        }

        // 验证手机号码格式
        if (!validatePhoneNumber(phoneNumber)) {
            alert("请输入正确的手机号码");
            return;
        }

        // 发送手机号码到后端
        $.ajax({
            url: "controller/public/SendSms.php",
            type: "POST",
            data: { phoneNumber: phoneNumber },
            success: function(response) {
                // 处理成功响应的代码
                // console.log(response);
                 alert("验证码发送成功");
            },
            error: function() {
                // 处理错误响应的代码
                alert("发送验证码失败");
            }
        });

        // 禁用获取验证码按钮
        $("#get_verification_code").prop("disabled", true);

        // 开始倒计时
        var countdown = 60;
        var countdownText = $("#countdown");
        countdownText.text(countdown + "秒后重新获取");

        var countdownInterval = setInterval(function() {
            countdown--;
            countdownText.text(countdown + "秒后重新获取");

            if (countdown <= 0) {
                // 倒计时结束，解除禁用获取验证码按钮
                clearInterval(countdownInterval);
                countdownText.text("");
                $("#get_verification_code").prop("disabled", false);
            }
        }, 1000);
    });

    // 监听保存提交按钮的点击事件
    $("#submit_btn_rename").click(function() {
        // 获取表单数据
        var renameData = {
            proxy_rename: $("#proxy_rename").val(),
            proxy_uid: $("#proxy_uid").val(),
            proxy_phone: $("#proxy_phone").val(),
            verification_code: $("#verification_code").val(),
        };

        // 发送Ajax请求
      $.ajax({
        url: "controller/DoUpProxy.php",
        type: "POST",
        data: renameData,
        dataType: "json",
        success: function(response) {
            // 处理成功响应的代码
            alert(response.msg);
            
            if (response.code === 2) {
                // 隐藏或关闭模态框
                $('#rename-modal').modal('hide');
                    $('#rename-modal').on('hidden.bs.modal', function() {
                        $(this).remove();
                         location.reload();
                    });
            }
        },
        error: function() {
            // 处理错误响应的代码
            alert("系统出错，请稍后再试！");
        }
      });

    });

     // 监听保存提交按钮的点击事件
    $("#submit_btn_alipay").click(function() {
        // 获取表单数据
        var alipayData = {
            alipay_name: $("#alipay_name").val(),
            alipay_acc: $("#alipay_acc_input").val(),
        };

        // 发送Ajax请求
       $.ajax({
        url: "controller/DoUpProxy.php",
        type: "POST",
        data: alipayData,
        dataType: "json",
        success: function(response) {
            // 处理成功响应的代码
            alert(response.msg);
            // console.log(response);
            if (response.code === 2) {
                // 隐藏或关闭模态框
                $('#alipay-modal').modal('hide');
                    $('#alipay-modal').on('hidden.bs.modal', function() {
                        $(this).remove();
                         location.reload();
                    });
            }
        },
        error: function() {
            // 处理错误响应的代码
            alert("系统出错，请稍后再试！");
        }
       });

    });

     // 监听保存提交按钮的点击事件
    $("#submit_btn_banks").click(function() {
        // 获取表单数据
        var bankData = {
            bank_name: $("#bank_names").val(),
            bank_acc: $("#bank_accs").val(),
            proxy_bank_name: $("#proxy_bank_names").val(),
            proxy_bank_zh: $("#proxy_bank_zhs").val()
        };
        
        // console.log(bankData);
        // 发送Ajax请求
      $.ajax({
        url: "controller/DoUpProxy.php",
        type: "POST",
        data: bankData,
        dataType: "json",
        success: function(response) {
            // 处理成功响应的代码
            alert(response.msg);
            
            if (response.code === 2) {
                // 隐藏或关闭模态框
                $('#bank-modal').modal('hide');
                    $('#bank-modal').on('hidden.bs.modal', function() {
                        $(this).remove();
                         location.reload();
                    });
            }
        },
        error: function() {
            // 处理错误响应的代码
            alert("系统出错，请稍后再试！");
        }
      });

    });
});


</script>
 <?php require_once('common/footer.php'); ?>  
 <?php
} else {
  echo "<script>alert('登录过过期，没有权限访问该页面');location.href='login.html';</script>";
}